using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using WebControls;
using BusinessLayer;
using EntityLayer;
using InfraStructureLayer;

public partial class SFMaster : SFMasterPage
{
    protected void Page_Load(object sender, EventArgs e)
    {
        
        if (!Page.IsPostBack)
        {
            rptLanguages.DataSource = CurrentContext.Languages;
            rptLanguages.DataBind();
            DataTable dt = CurrentContext.Menu.Clone();

            foreach (DataRow dr in CurrentContext.Menu.Select("LanguageId=" + CurrentContext.LanguageId.ToString() + " AND ParentMenuId IS NULL"))
            {
                if (!Convert.ToBoolean(dr["IsAdminMenu"]) || CurrentContext.UserId != null)
                {
                    dt.ImportRow(dr);
                }
            }

            rptMenu.DataSource = dt;
            rptMenu.DataBind();

            uctAdminMenu1.Visible = IsAdminMenuVisible();

        }

    }


    protected void rptLanguages_ItemCommand(object source, RepeaterCommandEventArgs e)
    {
        if (e.CommandName == "Language")
        {
            Session["LanguageId"] = Convert.ToInt32(e.CommandArgument);
            //((SFPage)this.Page).SetLanguage();
            //HttpCookie insHttpCookie = new HttpCookie("Language");
            //insHttpCookie.Expires = DateTime.Now.AddYears(1);
            //insHttpCookie["LanguageId"] = e.CommandArgument.ToString();
            //Response.Cookies.Add(insHttpCookie);
            //UctCalendar1.SetDate();
            Response.Redirect("/" + CurrentContext.Language + "/default.aspx");
        }
    }

    protected void btnSave_Click(object sender, EventArgs e)
    {
        ((SFPage)this.Page).Save();
    }
    protected void btnClose_Click(object sender, EventArgs e)
    {
        ((SFPage)this.Page).CloseEditPanel();
    }

    protected void lbtClose_Click(object sender, EventArgs e)
    {
        ((SFPage)this.Page).CloseEditPanel();

    }
    protected void btnSearch_Click(object sender, EventArgs e)
    {
        if (txtSearch.Text.Trim() != "")
        {
            Session["SearchText"] = txtSearch.Text;
            Response.Redirect("~/searchResults.aspx");
        }
    }
    protected bool IsAdminMenuVisible()
    {
        if(CurrentContext.UserId.HasValue)
        {
            return (CurrentContext.UserId.Value > 0);
        }
        else
        {
            return false;
        }
    }
}
